import { createApp } from "vue";
import router from "./router"; //导出的路由注入
import "./style.css";
import "./assets/iconfont/iconfont.css"; //引入iconfont图标样式
import pinia from "./store";
import mitt from "mitt"; //引入mitt
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import App from "./App.vue";
import { _get, _post, _put, _delete, http } from "./utils/axios";
import { directives } from "./utils/directives"; //引入自定义指令集合
// 让elemenPlus组件中的英文变中文
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn"; //中文
// import locale from "element-plus/lib/locale/lang/zh-cn"; //中文
import BaiduMap from "vue-baidu-map-3x"; //全局引入百度地图
import { registerIcons } from "@/utils/common"; //全局注册Icon组件
import "default-passive-events";
import { loadLang } from "@/lang/index";
import ganttastic from "@infectoone/vue-ganttastic";

const app = createApp(App);
// const store = createPinia();
const Mit = mitt();
//为mitt 注册ts类型 ts扩展
declare module "vue" {
  export interface ComponentCustomProperties {
    $Bus: typeof Mit;
  }
}
//给路由元信息meta扩展类型
declare module "vue-router" {
  interface RpiteMeta {
    title: "string";
    authorization: boolean;
  }
}
dayjs.locale("zh-cn"); // 全局使用中文 甘特图中文
app.use(router);
app.use(pinia); //vue4版本的vuex
app.use(ganttastic); //甘特图
app.use(BaiduMap, {
  // ak: "wZcU7ugfOpZLuuRTAvNPn3Y36rpFxp1Q",
  ak: "xFpQIDULotAyanlviGUOf0IEOcdP0qMA",
  // v:'2.0',  // 默认使用3.0
  v: "3.0",
  // type: 'WebGL' // ||API 默认API  (使用此模式 BMap=BMapGL)
});

app.config.globalProperties.$_get = _get;
app.config.globalProperties.$_post = _post;
app.config.globalProperties.$_put = _put;
app.config.globalProperties.$_delete = _delete;
app.config.globalProperties.eventBus = Mit;

// 从 @element-plus/icons-vue 中导入所有图标并进行全局注册
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  // console.log(key);
  app.component(key, component);
}

// Object.keys(ElementPlusIconsVue).forEach((key) => {
//   console.log(key);
//   app.component(
//     key,
//     ElementPlusIconsVue[key as keyof typeof ElementPlusIconsVue]
//   );
// });
async function start() {
  const i18n = await loadLang(app);
  app.use(ElementPlus, { i18n: i18n.global.t });
}
start();

// 全局注册
directives(app); // 自定义指令 目前只有点击后自动失焦指令
registerIcons(app); //icons组件

app.mount("#app");
